<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="common" th:with="title='个人资料'"></head>
<body class="hold-transition skin-blue sidebar-mini">
	<div th:include="main-header"></div>
	<div class="content-wrapper">
		<section class="content">
			<div class="panel panel-default" style="height: 100%;">
				<div class="row">
					<div class="col-md-6">
						<div class="box-header with-border">
							<h3 class="box-title">用户信息</h3>
						</div>
						<div class="box-body">
							<label>当前用户：
								<p style="display: inline-block" data-th-text="${user.username}"></p>
							</label><br /> <label>昵称：
								<p style="display: inline-block" data-th-text="${user.nickname}"></p>
							</label><br /> <label>角色：
								<p style="display: inline-block" data-th-text="${user.role.rolename}"></p>
							</label>
						</div>
						<div class="box-header with-border">
							<h3 class="box-title">修改密码</h3>
						</div>
						<form id="passwordform" role="form" method="post" action="/user/updatapassword">
							<div class="box-body">
								<div class="form-group">
									<label for="exampleInputPassword1">当前密码</label> <input
										type="password" class="form-control" data-th-value="${oldpassword}"
										name="oldpassword" id="oldpassword" required>
								</div>
								<div class="form-group">
									<label for="exampleInputPassword1">新密码</label> <input
										type="password" class="form-control nospace" name="newpassword"
										id="newpassword" required minlength="6" maxlength="20">
								</div>
								<div class="form-group">
									<label for="exampleInputPassword1">重复新密码</label> <input
										type="password" class="form-control" name="repeatpassword"
										id="repeatpassword" required />
								</div>
							</div>
							<div class="box-footer">
								<button type="submit" class="btn btn-primary">确认</button>
							</div>
						</form>
						</form>
						<div data-th-if="${errmsg}!=null"
							class="alert alert-warning alert-dismissible">
							<button type="button" class="close" data-dismiss="alert"
								aria-hidden="true">&times;</button>
							<p data-th-text="${errmsg}" style="text-align:center"></p>
						</div>
						<div data-th-if="${sucmsg}!=null"
							class="alert alert-success alert-dismissible">
							<button type="button" class="close" data-dismiss="alert"
								aria-hidden="true">&times;</button>
							<p data-th-text="${sucmsg}" style="text-align:center"></p>
						</div>
					</div>
				</div>
			</div>
		</section>
	</div>
	<div th:include="main-footer"></div>
	<script>
		jQuery.validator.addMethod("nospace", function(value) {
			console.log(value);
			let p = /\s/;
			console.log(!p.test(value));
		    return !p.test(value);
		}, "新密码不能包含空格");
		$(function(){
	        $("#passwordform").validate({
	        	rules:{
	        		repeatpassword:{
	        			equalTo:"#newpassword"
	        		}
	        	},
	        	messages:{
	        		repeatpassword:{
	        			equalTo:"两次输入的密码不一致"
	        		}
	        	}
	        });
	    });
	</script>
</body>
</html>
